<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>快排</title>
</head>
<body>

</body>
<script>
    let arr = [3, 2, 1, 4, 6, 5, 7, 9, 8, 0];

    function swap(arr, idx1, idx2) {
        let temp = arr[idx1];
        arr[idx1] = arr[idx2];
        arr[idx2] = temp;
    }

    function partition(arr, left, right) {
        let v = arr[left];
        l = left;
        for (let i = left + 1; i <= right; i++) {
            if (arr[i] < v) {
                swap(arr, i, l + 1);
                l++;
            }
        }
        swap(arr, left, l);
        return l;
    }

    function quickSort(arr, left, right) {
        if (left >= right) {
            return;
        }
        let pivot = partition(arr, left, right);
        quickSort(arr, left, pivot - 1);
        quickSort(arr, pivot + 1, right);
    }

    quickSort(arr, 0, arr.length - 1);
    console.log(arr);
</script>
</html>
